/*

This software is OSI Certified Open Source Software.
OSI Certified is a certification mark of the Open Source Initiative.

The license (Mozilla version 1.0) can be read at the MMBase site.
See http://www.MMBase.org/license

*/

package org.mmbase.module.community;

import java.util.Date;

import org.mmbase.util.logging.Logger;
import org.mmbase.util.logging.Logging;

/**
 * Creates a timestamp value out of two integer values.
 * Supposedly needed because the Informix setup had no configuration
 * for long values (in which the timestamps are expressed), which
 * means they need be store as two integers instead.
 * @deprecated Do not use this class. Store timestamps as Long or Date instead.
 *
 * @author Dirk-Jan Hoekstra
 * @author Pierre van Rooden
 * @version 28 May 2001
 */

public class TimeStamp extends Date {

    // logger
    private static Logger log = Logging.getLoggerInstance(TimeStamp.class.getName());

    /**
     * the 16 least significant bits of the timestamp value
     */
    private int low = 0;
    /**
     * the 16 most significant bits of the timestamp value
     */
    private int high = 0;

    /**
     * Creates a TimeStamp based on the current time.
     */
    public TimeStamp() {
        this(System.currentTimeMillis());
    }

    /**
     * Creates a TimeStamp based on a specified time.
     * @param time the time in milliseconds since 1/1/1970
     */
    public TimeStamp(long time) {
        setTime(time);
        low  = (int)(time & 0xFFFFFFFFL);
        high = (int)(time >>> 32);
    }

    /**
     * Creates a TimeStamp based on a specified time.
     * @param low the 16 least significant bits of a time value (a long
     *      representing milliseconds since 1/1/1970
     * @param high the 16 most significant bits of the time value
     */
    public TimeStamp(Integer low, Integer high) {
        this(low.intValue(), high.intValue());
    }

    /**
     * Creates a TimeStamp based on a specified time.
     * @param low the 16 least significant bits of a time value (a long
     *      representing milliseconds since 1/1/1970
     * @param high the 16 most significant bits of the time value
     */
    public TimeStamp(int low, int high) {
        long highlong = high;
        highlong <<= 32;
        long time;
        if (low<0) { // sign bit is up
            long lowlong = low;
            lowlong &= 0xFFFFFFFFL;
            time = highlong + lowlong;
        } else {
            time = highlong + low;
        }
        setTime(time);
    }

    /**
     * Retrieve the 16 least significant bits of a time value (a long
     * representing milliseconds since 1/1/1970.
     */
    public int lowIntegerValue() {
        return low;
    }

    /**
     * Retrieve the 16 most significant bits of a time value (a long
     * representing milliseconds since 1/1/1970.
     */
    public int highIntegerValue() {
        return high;
    }
}
